/*
 * @Author: yangrongxin
 * @Date: 2021-08-17 17:05:02
 * @LastEditors: yangrongxin
 * @LastEditTime: 2021-09-17 10:16:55
 */
import { useEffect, useState } from 'react';
import { ScrollView, View, Text, Image } from '@tarojs/components';
import Taro from '@tarojs/taro';
import { setItemSync } from '@/utils/storage';
import { STORAGE_TYPE } from '@/const/dataDictionary';
import { getCurrentTeamAdmin } from '../../service';
import styles from './index.module.less';

const TeamPage = (props: any) => {
  const { isLogin } = props;

  const [refresherTrigger, setRefresherTrigger] = useState<boolean>(false);

  useEffect(() => {
    Taro.setNavigationBarTitle({
      title: '',
    });
    Taro.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#f7f6ff',
    });
  }, []);

  const fetchTeamData = () => {
    getCurrentTeamAdmin().then((res: any) => {
      if (res?.teamMainUser === 1) {
        setItemSync(STORAGE_TYPE.TEAMMAINUSER, res.teamMainUser);
        Taro.reLaunch({
          url: '/pages/Team/index',
        });
      }
    });
    setTimeout(() => {
      setRefresherTrigger(false);
    }, 500);
  };

  return (
    <ScrollView
      scrollWithAnimation
      scrollY
      refresherEnabled={isLogin}
      onRefresherRefresh={() => {
        setRefresherTrigger(true);
        fetchTeamData();
      }}
      refresherTriggered={refresherTrigger}
    >
      <View className={styles.container}>
        {/* 展示顶部的元素 */}
        <View className={styles.headerImg}>
          <Image src="https://hxgywx.oss-cn-shenzhen.aliyuncs.com/hxt-wxminiprogram/top_title.png" />
        </View>
        {/* TODO: 展示团体需求问卷的跳转 */}
        {/* <View className={styles.teamQuestion}>
          <Text>团体需求问卷</Text>
          <View
            onClick={() => {
              console.log('isTeamAdminTrue');
              setItemSync('isTeamAdmin', { isTeamAdmin: true });
            }}
          >
            <Text>去填写</Text>
          </View>
        </View> */}
      </View>
    </ScrollView>
  );
};

export default TeamPage;
